export const takeNumbers = (num, dot = 2) => {
  const parsedNum = parseFloat(num);
  if (isNaN(parsedNum)) return null;

  const units = [
    { value: 100000000, label: '亿' },
    { value: 10000, label: '万' }
  ];

  for (const { value, label } of units) {
    if (parsedNum >= value) {
      return `${(parsedNum / value).toFixed(dot)}${label}`;
    }
  }
  return parsedNum.toFixed(dot);
};
export const takeTime = (time) => {
  const now = new Date().getTime();
  const timestamp = new Date(time).getTime();
  const diff = now - timestamp;

  // 转换为分钟、小时、天数等
  const minutes = Math.floor(diff / (1000 * 60));
  const hours = Math.floor(diff / (1000 * 60 * 60));
  const days = Math.floor(diff / (1000 * 60 * 60 * 24));

  // 根据时间差返回对应的描述
  if (minutes < 1) return '刚刚';
  if (minutes < 60) return `${minutes}分钟前`;
  if (hours < 24) return `${hours}小时前`;
  if (days < 30) return `${days}天前`;
  return new Date(time).toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
  }).replace(/\//g, '-');
};
export const takeTimeBase = (time,gap='-') => {
  return new Date(time).toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
  }).replace(/\//g, gap);
}


import {chooseTagTime,chooseTagType,chooseTagLong} from "@/assets/baseInfo.js";
// 获取首页数据
export const getDataBase = (num) => {
  let list = [];
  for (let i = 0; i < num; i++) {
  list.push({
    id: i,
    title: `标题标题${i}`,
    average_score: `${Math.floor(Math.random() * 10)}.5`,
    img: "@/assets/image/user.jpg",
    num:`${i*Math.random()*100}`,
    showTag:[
      chooseTagTime[Math.floor(Math.random() * (chooseTagTime.length - 1)) + 1],
      chooseTagType[Math.floor(Math.random() * (chooseTagType.length - 1)) + 1],
      chooseTagLong[Math.floor(Math.random() * (chooseTagLong.length - 1)) + 1]
    ]
  });
}
return list;
}
// 获取详情页数据
export const getDetailData = (id) => {
  const commentList=[];
  for(let i=0;i<10;i++){
    let obj = {
      userName: `用户${i}`,
      userImg: "@/assets/image/user.jpg",
      content: `评论内容评论内容评论内容评论内容评论内容评论内容${i}`,
      time: new Date(Date.now() - Math.floor(Math.random()*12 * 30 * 24 * 60 * 60 * 1000)),
      average_score: `${Math.floor(Math.random() * 10)}.5`,
      like: Array.from({length: Math.floor(Math.random() * 100)}, () => Math.floor(Math.random() * 1000)),
      noLike: Array.from({length: Math.floor(Math.random() * 100)}, () => Math.floor(Math.random() * 1000)),
      isLiked: false,
      isDisLiked: false,
    }
    commentList.push(obj);
  }
  return {
    id: id,
    title: `标题标题${id}`,
    score: `${Math.floor(Math.random() * 10)}.5`,
    img: "@/assets/image/user.jpg",
    num:`${id*Math.random()*100}`,
    info:`简介简介简介简介简介${id}`,
    actor:`主演${id}`,
    director:`导演${id}`,
    time:`上映时间${id}`,
    comment:commentList,
  };
}
export const getUserInfo = () => {
  let random = Math.floor(Math.random()*1000);
  return {
    userId: random,
    userName: `用户${random}`,
    nickName: `昵称${random}`,
    userImg: '@/assets/image/user.jpg',
    sex: 0,
    average_score: random,
    comments:random,
    likes: random,
    noLikes: random,
    favorites: getDataBase(10),
    history: getDataBase(20),
  }
}
